import { axios } from '@/utils/request'

const api = {
  order: '/orders',
  orderAfterSale: '/orders/after-sale'
}

export function getOrderList (params) {
  return axios({
    url: api.order,
    method: 'get',
    responseType: params.hasOwnProperty('export') && !params.hasOwnProperty('async') ? 'blob' : 'json', // 导出 下载
    params
  })
}

export function cancelOrderByNumbering (numbering, option = {}) {
  return axios(
    Object.assign({
      url: `${api.order}/${numbering}`,
      method: 'delete'
    }, option)
  )
}

export function getOrderInfo (id) {
  return axios({
    url: `${api.order}/${id}`,
    method: 'get'
  })
}

export function getAfterSaleOrderList (params) {
  return axios({
    url: api.orderAfterSale,
    method: 'get',
    responseType: params.hasOwnProperty('export') ? 'blob' : 'json', // 导出 下载
    params
  })
}

export function getAfterSaleOrderInfo (id) {
  return axios({
    url: `${api.orderAfterSale}/${id}`,
    method: 'get'
  })
}

export function patchOrderExpressDelivery (data, option = {}) {
  return axios(
    Object.assign({
      url: `${api.order}/express-delivery`,
      method: 'patch',
      data
    }, option)
  )
}

export function patchOrderRemark (data) {
  return axios({
    url: `${api.order}/remark`,
    method: 'patch',
    data
  })
}

export function afterSaleOrderAudit (data) {
  return axios({
    url: `${api.orderAfterSale}/audit/${data.id}`,
    method: 'post',
    data
  })
}

export function patchOrderReceivingInformation (id, data) {
  return axios({
    url: `${api.order}/${id}/receiving-information`,
    method: 'patch',
    data
  })
}
